//
//  DateWithLunaView.swift
//  YOKO
//
//  Created by Zoe_G on 16/5/5.
//  Copyright © 2016年 guozhzh. All rights reserved.
//

import UIKit

class DateWithLunaView: UIView {
    
    
    @IBOutlet weak var datelabel: UILabel!
    
    @IBOutlet weak var lunalabel: UILabel!
    
    @IBOutlet weak var selectedView: UIView!
    
    var date: NSDate?{
        didSet{
            updateUI()
        }
    }
    
    var isSelected: Bool = false{
        didSet{
            updateSelectView()
        }
    }
    var isCurrentMonthDate: Bool = true
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        
    }
    
    func updateUI(){
        
        if date != nil {
            
            lunalabel.text = NSDate.getLunaString(date!)
            lunalabel.numberOfLines = 0
            
            datelabel.text = String(format: "%02d", NSDate.day(date!))
            
            if NSCalendar.currentCalendar().isDateInToday(date!){
                self.layer.borderWidth = 1.0
                self.layer.borderColor = YOKOColor.TypeColors[1].CGColor
            }else{
                self.layer.borderColor = UIColor.lightGrayColor().CGColor
                self.layer.borderWidth = 0
            }
        }
        
        if isCurrentMonthDate{
            datelabel.textColor = UIColor.blackColor()
        }else{
            datelabel.textColor = UIColor.lightGrayColor()
            self.backgroundColor = YOKOColor.backImageColor
        }
    }
    
    func updateSelectView(){
        if isSelected{
            selectedView.backgroundColor = YOKOColor.TypeColors[1]
        }else{
            selectedView.backgroundColor = UIColor.clearColor()
        }
    }
    
    override func drawRect(rect: CGRect) {

        DrawUtil.drawLine(CGPointMake(0, 0), end: CGPointMake(0, self.frame.height), withColor: UIColor.lightGrayColor(), withWidth: 0.5)
    }

}
